package core;

import java.io.IOException;
import java.io.ObjectOutputStream;
import java.io.FileOutputStream;
import java.io.Serializable;

import core.reports.ReportData;

/**
 * An implementation of ISaver that uses Java Serialization.  This implementation expects to
 * be given a location on disk that it can write to.
 * @author Royce
 *
 */
public class SerializableSaver implements ISaver, Serializable {

	private static final long serialVersionUID = 6912429999466427323L;
	/**
	 * The ObjectOutputStream used to write objects to disk
	 */
	private ObjectOutputStream outStream;
	
	/**
	 * Default Constructor
	 */
	public SerializableSaver() {
		
	}


	/**
	 * @inheritDoc
	 * Saves a Tracker object to the default location.
	 */
	@Override
	public void save() throws IOException {
		outStream = new ObjectOutputStream(new FileOutputStream("tracker.tkr"));
		outStream.writeObject(RootStorageUnit.instance());
		outStream.writeObject(ItemManager.instance());
		outStream.writeObject(ProductManager.instance());
		outStream.writeObject(ReportData.instance());
		outStream.close();
	}
	
}
